﻿using System.Linq.Expressions;
using SqlSugar;
using Vin.Extension.Framework.Base;
using Vin.Extension.Framework.Entities;
using Vin.Extension.Framework.Repository;
using Vin.Tool.Attributes;

namespace Vin.Extension.Framework.Implement;

public class
    VinFrameworkBaseRecordRepositoryServiceAsync<TBaseRepository, TRepositoryEntity> :
    VinFrameworkBaseService
    where TRepositoryEntity : VinFrameworkBaseRecordEntity, new()
    where TBaseRepository : class, IVinFrameworkBaseRecordRepository<TRepositoryEntity>
{
    [Inject] protected readonly TBaseRepository _baseRepository = null!;

    public virtual Expressionable<TRepositoryEntity> CreateExpressionable(
        Expression<Func<TRepositoryEntity, bool>>? expression = null)
    {
        return Expressionable.Create<TRepositoryEntity>()
            .AndIF(expression != null, expression);
    }
}